package cn.knowei.web;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.InputStream;
import java.sql.*;

/**
 * @Author: knowei
 * @Description:
 * @Date: Create in 23:06 2023-03-15
 */
public class test {

    String url = "jdbc:mysql://localhost:3306/zhengliwen?serverTimezone=GMT%2B8";
    String user = "root";
    String password = "1234";
    Connection con;
    Statement stmt;
    ResultSet rs;


    @Before
    public void aft() throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        con = DriverManager.getConnection(url, user, password);
        stmt = con.createStatement();
        System.out.println(1);
    }

    /**
     * 遍历
     * @throws ClassNotFoundException
     * @throws SQLException
     */
    @Test
    public void test02() throws ClassNotFoundException, SQLException {

        rs = stmt.executeQuery("SELECT * FROM students") ;

        while (rs.next()) {
            System.out.println(rs.getString("username"));
        }
        con.close();
    }

    @After
    public void close() throws SQLException {
        rs.close();
        stmt.close();
        con.close();
    }
}
